package edu.ustb.mis.dm.model.unit.template;

import java.io.Serializable;
import edu.ustb.mis.dm.model.attributes.interfaces.Attributes;
import edu.ustb.mis.dm.model.unit.interfaces.Item;

/**
 * Instance的一个模板类，定义了instanceName,instanceType的初始化方式,对于未知类型的实例进行聚类时，将instanceType置为UNKNOWN_TYPE
 * 
 * @author Saya 2011-5-23
 */
public abstract class AbstractItem<T extends Attributes<?, ?>> implements Item<T>, Serializable {
	private static final long serialVersionUID = 7348182617606884207L;

	protected String instanceName;

	protected String instanceType = UNKNOWN_TYPE;

	protected T attributes;

	public static final String UNKNOWN_TYPE = "";

	public AbstractItem() {
	}

	public String getInstanceName() {
		return instanceName;
	}

	public void setInstanceName(String instanceName) {
		this.instanceName = instanceName;
	}

	public String getInstanceType() {
		return instanceType;
	}

	public void setInstanceType(String instanceType) {
		this.instanceType = instanceType;
	}

	public String getInstanceId() {
		return this.instanceName + this.instanceType;
	}

	public T getAttributes() {
		return this.attributes;
	};

	public void setAttributes(final T attributes) {
		this.attributes = attributes;
	};
	
	public int attributesSize(){
		return this.attributes.size();
	}

	@Override
	public String toString() {
		return getInstanceId() + getAttributes().toString();
	}
}
